home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / Tickle-4.0 (tcl) / library / help / tcl / files / dup < prev    next >
Encoding:
Text File  |  1993-10-26  |  1.5 KB  |  35 lines  |  [TEXT/$Tcl]

  1.  
  2.  
  3.           dup fileId ?targetFileId?
  4.                Duplicate an open file.  A new file id is  opened  that
  5.                addresses the same file as fileId.
  6.  
  7.                If targetFileId is specified, the the file  is  dup  to
  8.                this  specified  file  id.   Normally  this  is  stdin,
  9.                stdout, or stderr.  The dup command will handle  flush-
  10.                ing  output  and  closing this file.  It is recommended
  11.                that the file not be closed in advanced if it is one of
  12.                stdin,  stdout,  or  stderr.  Otherwise internal C code
  13.                that uses one of these files via direct access to stdio
  14.                FILE struct may fail.
  15.  
  16.                The procedure shown below will create a  child  process
  17.                and  set  its standard input and output files to a pair
  18.                of pipe files we pass as arguments.  Finally  the  pro-
  19.                gram  does  an  execl  of a specified command, with the
  20.                program's stdin and stdout coming from and going to our
  21.                pair of pipes.
  22.  
  23.                    proc ChildProcess {cmd inPipe outPipe} {
  24.                        if {[set childPid [fork]] == 0} {
  25.                            dup $inPipe stdin
  26.                            close $inPipe
  27.                            dup $outPipe stdout
  28.                            close $outPipe
  29.  
  30.                            execl $cmd
  31.                            # will never make it here...
  32.                        }
  33.                        return $childPid
  34.                    }
  35.